#!/bin/bash

# SFT训练启动脚本

# 检查参数
if [ "$#" -lt 1 ]; then
    echo "Usage: $0 <config_file> [additional_args...]"
    echo "Example: $0 configs/default_config.py"
    exit 1
fi

# 获取参数
CONFIG_FILE=$1
shift

# 获取脚本所在目录的绝对路径
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

# 切换到项目根目录
cd "$PROJECT_ROOT" || exit 1

# 检查配置文件是否存在
if [ ! -f "$CONFIG_FILE" ]; then
    echo "Error: Config file '$CONFIG_FILE' not found!"
    exit 1
fi

# 设置环境变量
export PYTHONPATH="$PROJECT_ROOT:$PYTHONPATH"
export TOKENIZERS_PARALLELISM=false

# 启动训练
echo "Starting SFT training with config: $CONFIG_FILE"
python3 scripts/train_sft.py "$CONFIG_FILE" "$@"